package com.sanen.flyer.entity.hero;

import com.sanen.flyer.common.Constant;
import com.sanen.flyer.entity.Aircraft;
import com.sanen.flyer.entity.Bullet;
import com.sanen.flyer.entity.Jet;
import com.sanen.flyer.entity.enemy.Enemy;
import com.sanen.flyer.factory.BulletFactory;
import com.sanen.flyer.main.Game;
import com.sanen.flyer.tool.Console;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wsse
 * @date 2018-09-06 19:20
 */
public abstract class Hero extends Aircraft {

    protected Jet jetL;
    protected Jet jetR;
    @Override
    public boolean outOfBounds() {
        return false;
    }

    @Override
    public boolean touchBounds() {
        if (x<=0||y<=0||x+width>= Game.WIDTH||y+height>Game.HEIGHT)return true;
        return false;
    }
    public abstract List<Bullet> shoot();

    @Override
    public void draw(Graphics g) {
        jetL.draw(g);
        jetR.draw(g);
        super.draw(g);
    }

    @Override
    public void move() {
        if (Game.isPress("w")) {
            y -= (int) speedy;
            sumy -= speedy - (int) speedy;

        }
        if (Game.isPress("s")) {//后退为前进三分之二的速度
            y += (int) (speedy*0.8);
            sumy += speedy*0.8 - (int) (speedy*0.8);

        }
        if (Game.isPress("a")) {
            x -= (int) speedx;
            sumx -= speedx - (int) speedx;
        }
        if (Game.isPress("d")) {
            x += (int) speedx;
            sumx += speedx - (int) speedx;
        }

        if (sumx >= 1) {
            this.x += 1;
            sumx--;
        } else if (sumx <= -1) {
            x -= 1;
            sumx++;
        }

        if (sumy >= 1) {
            y += 1;
            sumy--;
        } else if (sumy <= -1) {
            y -= 1;
            sumy++;
        }

        if (x <= 0) x = 0;
        else if (x >= windowWidth-width) x = windowWidth - width;
        if (y <= 0) y = 0;
        else if (y >= windowHeight - height) y = windowHeight- height;
        jetL.move();
        jetR.move();
    }

    public boolean byHit(Enemy e){
        return true;
    }

}
